package edu.unc.comp410.colemangeer.model;

import org.apache.log4j.Logger;

/*In lieu of specifying the tax rules for each state,
Use California tax rates for all states/provinces that begin with
	the letters A-G
Use North Carolina tax rates for all states/provinces that begin with
	the letters H-S
Use Texax tax rates for all states/provinces that begin with
	the letter T.
No tax for all states/provinces that begin with the letters U-Z*/

public enum TaxRegion {
	NC,CA,TX,NO_TAX;
	
	private static Logger log = Logger.getLogger(TaxRegion.class);
	
	public static TaxRegion determineTaxRegion(String region) throws TaxRuleException{
		
		if (region==null || region.length()!=2)
			throw new IllegalArgumentException();
		if (region.equalsIgnoreCase("CA")){
			return CA;
			
		}
		else if (region.equalsIgnoreCase("NC")){
			return NC;
		}
		
		else if (region.equalsIgnoreCase("TX")){
			return TX;
		}
		else{
			
			// apply the alphabetical rules
			
			String firstChar = region.toString().substring(0, 1).toUpperCase();
			
			if (firstChar.compareTo("A") > 0 && firstChar.compareTo("H")< 0){
				return CA;
			}
			else if (firstChar.compareTo("G") > 0 && firstChar.compareTo("T")< 0){
				return NC;
			}
			
			//Texas!
			else if (firstChar.compareTo("T")== 0){
				return TX;
			}
			
			else{
			
			return NO_TAX;
			}
		}
		
	}
}
